<template>
    <ex-dialog width="1000px" class="ex-diolog" :title="title" :visible="visible" @closeDialog="handleClose">
        <el-form ref="form" :model="form" :rules="rules" label-width="140px">
            <el-form-item label="是否启用公告:">
                <el-switch v-model="form.showType" active-text="是" :active-value="'0'" inactive-text="否" :inactive-value="'1'"></el-switch>
            </el-form-item>
            <el-form-item label="公告轮播时间:" prop="date">
                <el-date-picker v-model="form.date" type="datetimerange" format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :style="{ width: inputWidth }">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="公告轮播内容:" prop="notice">
                <el-input type="textarea" :autosize="{ minRows: 6, maxRows: 10}" placeholder="请输入内容" v-model="form.notice" :style="{ width: inputWidth }"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm('form')" :loading="sumitLoading">保存提交</el-button>
            <el-button @click="handleClose">取 消</el-button>
        </div>
    </ex-dialog>
</template>
  
<script>
import {
    homePageNotice,homePageNoticeSet
} from '@/api/incentiveManagement/adConfigNew'
export default {
    // dicts: ['asset_card_type'],
    name: "Dialog",
    props: {
        visible: Boolean,
        id: String,
        pathType: String,
    },
    data() {
        return {
            inputWidth: '400px',
            sumitLoading: false,
            loading: false,
            title: "公告配置",
            form: {
                beginTime: '', //轮播开始时间
                endTime:'',//轮播结束时间
                notice:'',//公告内容
                showType:'1', //是否开启轮播，0开启，1关闭
                date:[],
            },
            // 表单校验
            rules: {
                date: [{
                    required: true,
                    message: "请选择时间",
                    trigger: ['change', 'blur'],
                }],
                notice: [{
                    required: true,
                    message: "请输入公告轮播内容",
                    trigger: ['change', 'blur'],
                }],
            },
        };
    },
    created() {
        this.getDetial()
    },
    methods: {
        //获取详情
        getDetial() {
            var data = {}
            homePageNotice(data).then(res => {
                this.form = res.result
                this.$set(this.form,'date',[])
                if(res.result.beginTime!=''){
                    this.form.date = [res.result.beginTime,res.result.endTime]
                }else{
                    this.form.date = []
                }
            })
        },
        //取消
        handleClose(formName) {
            this.$emit('update:visible', false)
        },
        //确认
        handleConfirm() {
            this.$emit('success')
        },
        /** 执行按钮 */
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if(this.form.date.length!=0){
                        this.form.beginTime = this.form.date[0]
                        this.form.endTime = this.form.date[1]
                    }
                    var data = {
                       ...this.form
                    }
                    this.sumitLoading = true
                    homePageNoticeSet(data).then(response => {
                        this.$message.success('执行成功');
                        this.$emit('success')
                        this.handleClose();
                        this.sumitLoading = false;
                    }).catch(() => {
                        this.sumitLoading = false;
                    });
                }
            });
        },
    }
};

</script>
<style scoped>
.main {
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px;
}

.icon_yes {
    font-size: 28px;
    color: #67c23a;
}

.el-select {
    width: 640px;
}

.el-button {
    margin: 0 20px;
}
.select-flow{
    width: 500px;
    white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
::v-deep .el-tag.el-tag--info{
    max-width: 300px;
    white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
</style>
  